

package com.mt.restaurant.controller.staff;

import org.springframework.security.access.prepost.PreAuthorize;
import com.mt.common.core.annotation.ApiPageParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.mt.common.core.web.base.PageDTO;
import com.mt.common.core.web.base.PageResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



import com.mt.restaurant.dto.staff.StaffAttendanceRecordsEditDto;
import com.mt.restaurant.entity.staff.StaffAttendanceRecords;
import com.mt.restaurant.service.staff.StaffAttendanceRecordsService;
					import com.mt.restaurant.service.staff.StaffService;
						

@Api(tags = "学生信息")
@RestController
@RequestMapping("/api/restaurant/staff/StaffAttendanceRecords")
@CrossOrigin(allowCredentials = "true")
public class StaffAttendanceRecordsController {
private static Logger logger = LoggerFactory.getLogger(StaffAttendanceRecordsController.class);



																		
																				@Autowired private StaffAttendanceRecordsService staffAttendanceRecordsService;
		@Autowired private StaffService staffService;
	
	/**
	* 根据分页参数查询学生信息集合
	*
	* @param pageDTO 分页条件
	*/
	@PreAuthorize("hasAuthority('restaurant:staff:StaffAttendanceRecords:view')")
	@ApiOperation("分页查询学生信息")
	@ApiPageParam
	@PostMapping("/findStaffAttendanceRecordss")
	public PageResultDTO findStaffAttendanceRecordss(@RequestBody PageDTO pageDTO){
		return this.staffAttendanceRecordsService.findStaffAttendanceRecordss(pageDTO);
	}

	/**
	* 根据ID查询指定的学生信息
	*
	* @param staffAttendanceRecordsId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:staff:StaffAttendanceRecords:view')")
	@ApiOperation("根据id查询学生信息")
	@ApiPageParam
	@PostMapping("/findStaffAttendanceRecords")
	public StaffAttendanceRecords findStaffAttendanceRecords(@RequestParam Long staffAttendanceRecordsId){
		return this.staffAttendanceRecordsService.findStaffAttendanceRecords(staffAttendanceRecordsId);
	}

	/**
	* 根据ID查询指定的学生信息(包含外键名称)
	*
	* @param staffAttendanceRecordsId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:staff:StaffAttendanceRecords:view')")
	@ApiOperation("根据ID查询指定的学生信息(包含外键名称)")
	@PostMapping("/findStaffAttendanceRecordsForView")
	public StaffAttendanceRecords findStaffAttendanceRecordsForView(@RequestParam Long staffAttendanceRecordsId){
		return this.staffAttendanceRecordsService.findStaffAttendanceRecordsWithForeignName(staffAttendanceRecordsId);
	}

	/**
	* 根据ID查询指定的学生信息(包含学生信息和外键名称)
	*
	* @param staffAttendanceRecordsId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:staff:StaffAttendanceRecords:view')")
	@ApiOperation("根据ID查询指定的学生信息(包含学生信息和外键名称)")
	@PostMapping("/findStaffAttendanceRecordsForEdit")
	public StaffAttendanceRecordsEditDto findStaffAttendanceRecordsForEdit(@RequestParam Long staffAttendanceRecordsId){
				StaffAttendanceRecordsEditDto staffAttendanceRecordsEditDto = new StaffAttendanceRecordsEditDto();
		staffAttendanceRecordsEditDto.setStaffAttendanceRecords(this.staffAttendanceRecordsService.findStaffAttendanceRecordsWithForeignName(staffAttendanceRecordsId));

		this.prepareStaffAttendanceRecordsEditDto(staffAttendanceRecordsEditDto);

		return staffAttendanceRecordsEditDto;
	}

	/**
	* 根据ID查询指定的学生信息(只提取ID 和 Name)
	*
	* @param staffAttendanceRecordsId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:staff:StaffAttendanceRecords:view')")
	@ApiOperation("根据ID查询指定的学生信息(只提取ID 和 Name)")
	@PostMapping("/findStaffAttendanceRecordssWithIdNameById")
	public StaffAttendanceRecords findStaffAttendanceRecordssWithIdNameById(@RequestParam Long staffAttendanceRecordsId){
	return this.staffAttendanceRecordsService.findStaffAttendanceRecordssWithIdNameById(staffAttendanceRecordsId);
	}

	/**
	* 根据名称查询学生信息集合(只提取ID 和 Name)
	*
	* @param staffAttendanceRecordsName 名称
	*/
	@PreAuthorize("hasAuthority('restaurant:staff:StaffAttendanceRecords:view')")
	@ApiOperation("根据名称查询学生信息集合(只提取ID 和 Name)")
	@PostMapping("/findStaffAttendanceRecordssWithIdNameByName")
	public List<StaffAttendanceRecords> findStaffAttendanceRecordssWithIdNameByName(@RequestParam String staffAttendanceRecordsName){
	return this.staffAttendanceRecordsService.findStaffAttendanceRecordssWithIdNameByName(staffAttendanceRecordsName);
	}


	/**
	* 创建新的学生信息
	*
	*/
	@PreAuthorize("hasAuthority('restaurant:staff:StaffAttendanceRecords:add')")
	@ApiOperation("创建新的学生信息")
	@PostMapping("/createStaffAttendanceRecords")
	public StaffAttendanceRecordsEditDto createStaffAttendanceRecords(){
				StaffAttendanceRecordsEditDto staffAttendanceRecordsEditDto = new StaffAttendanceRecordsEditDto();
		staffAttendanceRecordsEditDto.setStaffAttendanceRecords(new StaffAttendanceRecords());

		this.prepareStaffAttendanceRecordsEditDto(staffAttendanceRecordsEditDto);
		return staffAttendanceRecordsEditDto;
	}

	private void prepareStaffAttendanceRecordsEditDto(StaffAttendanceRecordsEditDto staffAttendanceRecordsEditDto){
															        //TODO: 以下代码可以注释掉，此行代码即时加载所有外键对象，以便选择。如果不在此加载，可以在界面上实现延迟加载。如果外键对象超过 500 行，建议采用延迟加载
		staffAttendanceRecordsEditDto.setStaffStaffs(this.staffService.findAllStaffsWithIdName());
																			}

	/**
	* 新增保存学生信息
	*
	* @param staffAttendanceRecords 实体对象
	*/
	@PreAuthorize("hasAuthority('restaurant:staff:StaffAttendanceRecords:add')")
	@ApiOperation("新增保存学生信息")
	@PostMapping("/saveStaffAttendanceRecords")
	public StaffAttendanceRecords saveStaffAttendanceRecords(@RequestBody StaffAttendanceRecords staffAttendanceRecords){
		return this.staffAttendanceRecordsService.saveStaffAttendanceRecords(staffAttendanceRecords);
	}

	/**
	* 修改保存学生信息
	*
	* @param staffAttendanceRecords 实体对象
	*/
	@PreAuthorize("hasAuthority('restaurant:staff:StaffAttendanceRecords:update')")
	@ApiOperation("修改保存学生信息")
	@PostMapping("/updateStaffAttendanceRecords")
	public StaffAttendanceRecords updateStaffAttendanceRecords(@RequestBody StaffAttendanceRecords staffAttendanceRecords){
		return this.staffAttendanceRecordsService.updateStaffAttendanceRecords(staffAttendanceRecords);
	}

	/**
	* 根据ID删除学生信息
	*
	* @param staffAttendanceRecordsId ID
	*/
	@PreAuthorize("hasAuthority('restaurant:staff:StaffAttendanceRecords:remove')")
	@ApiOperation("根据ID删除学生信息")
	@PostMapping("/deleteStaffAttendanceRecords")
	public void deleteStaffAttendanceRecords(@RequestParam Long staffAttendanceRecordsId){
		this.staffAttendanceRecordsService.deleteStaffAttendanceRecords(staffAttendanceRecordsId);
	}



}

